This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the Run button within the chunk or by placing your cursor inside it and pressing Ctrl+Shift+Enter.
library(velocyto.R)
载入需要的程辑包:Matrix
library(SeuratWrappers)
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
library(Seurat)
载入程辑包:‘Seurat’
The following objects are masked from ‘package:SeuratWrappers’:
ALRAChooseKPlot, ExportToCellbrowser, ReadAlevin, RunALRA, StopCellbrowser
source("tianfengRwrappers.R")
载入需要的程辑包:dplyr
载入程辑包:‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
载入需要的程辑包:reticulate
载入需要的程辑包:tidyr
载入程辑包:‘tidyr’
The following objects are masked from ‘package:Matrix’:
expand, pack, unpack
载入程辑包:‘MySeuratWrappers’
The following objects are masked from ‘package:Seurat’:
DimPlot, DoHeatmap, LabelClusters, RidgePlot, VlnPlot
载入程辑包:‘cowplot’
The following object is masked from ‘package:ggpubr’:
get_legend
载入需要的程辑包:viridisLite
载入程辑包:‘reshape2’
The following object is masked from ‘package:tidyr’:
smiths
NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow
Registered S3 method overwritten by 'enrichplot':
method from
fortify.enrichResult DOSE
clusterProfiler v3.14.3 For help: https://guangchuangyu.github.io/software/clusterProfiler
If you use clusterProfiler in published research, please cite:
Guangchuang Yu, Li-Gen Wang, Yanyan Han, Qing-Yu He. clusterProfiler: an R package for comparing biological themes among gene clusters. OMICS: A Journal of Integrative Biology. 2012, 16(5):284-287.
Registering fonts with R
载入程辑包:‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
载入需要的程辑包:Biobase
载入需要的程辑包:BiocGenerics
载入需要的程辑包:parallel
载入程辑包:‘BiocGenerics’
The following objects are masked from ‘package:parallel’:
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ, clusterExport, clusterMap,
parApply, parCapply, parLapply, parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from ‘package:dplyr’:
combine, intersect, setdiff, union
The following object is masked from ‘package:Matrix’:
which
The following objects are masked from ‘package:stats’:
IQR, mad, sd, var, xtabs
The following objects are masked from ‘package:base’:
anyDuplicated, append, as.data.frame, basename, cbind, colnames, dirname, do.call,
duplicated, eval, evalq, Filter, Find, get, grep, grepl, intersect, is.unsorted, lapply,
Map, mapply, match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, Position, rank,
rbind, Reduce, rownames, sapply, setdiff, sort, table, tapply, union, unique, unsplit,
which, which.max, which.min
Welcome to Bioconductor
Vignettes contain introductory material; view with 'browseVignettes()'. To cite
Bioconductor, see 'citation("Biobase")', and for packages 'citation("pkgname")'.
载入需要的程辑包:e1071
载入程辑包:‘widgetTools’
The following object is masked from ‘package:dplyr’:
funs
载入程辑包:‘DynDoc’
The following object is masked from ‘package:BiocGenerics’:
path
载入程辑包:‘DT’
The following object is masked from ‘package:Seurat’:
JS
========================================
circlize version 0.4.13
CRAN page: https://cran.r-project.org/package=circlize
Github page: https://github.com/jokergoo/circlize
Documentation: https://jokergoo.github.io/circlize_book/book/
If you use it in published research, please cite:
Gu, Z. circlize implements and enhances circular visualization
in R. Bioinformatics 2014.
This message can be suppressed by:
suppressPackageStartupMessages(library(circlize))
========================================
载入需要的程辑包:grid
========================================
ComplexHeatmap version 2.2.0
Bioconductor page: http://bioconductor.org/packages/ComplexHeatmap/
Github page: https://github.com/jokergoo/ComplexHeatmap
Documentation: http://jokergoo.github.io/ComplexHeatmap-reference
If you use it in published research, please cite:
Gu, Z. Complex heatmaps reveal patterns and correlations in multidimensional
genomic data. Bioinformatics 2016.
========================================
载入程辑包:‘ComplexHeatmap’
The following object is masked from ‘package:plotly’:
add_heatmap
#首先需要取并集,然后使用已有的umap,在其上绘制速率图
## AC
velodata1 <- ReadVelocity(file ="./velo_data/CARconHEL.loom")
reading loom file via hdf5r...
velodata2 <- ReadVelocity(file ="./velo_data/CARconHEA0620.loom")
reading loom file via hdf5r...
velodata3 <- ReadVelocity(file ="./velo_data/CARconHEA0717.loom")
reading loom file via hdf5r...
## PA
# velodata1 <- ReadVelocity(file ="./velo_data/CARconDIS.loom")
# velodata2 <- ReadVelocity(file ="./velo_data/CARconDIS0620.loom")
# velodata3 <- ReadVelocity(file ="./velo_data/CARconDIS0717.loom")
#匹配两次的barcode
func <- function(s)
{
s <- strsplit(s,".*:",fixed = F)[[1]][2]
s <- strsplit(s,"x",fixed = T)[[1]]
s <- paste(s,"1",sep = "-")
return(s)
}
velodata1[["spliced"]]@Dimnames[[2]] = as.character(lapply(velodata1[["spliced"]]@Dimnames[[2]],func))
velodata1[["unspliced"]]@Dimnames[[2]] = as.character(lapply(velodata1[["unspliced"]]@Dimnames[[2]],func))
velodata1[["ambiguous"]]@Dimnames[[2]] = as.character(lapply(velodata1[["ambiguous"]]@Dimnames[[2]],func))
func <- function(s)
{
s <- strsplit(s,".*:",fixed = F)[[1]][2]
s <- strsplit(s,"x",fixed = T)[[1]]
s <- paste(s,"3",sep = "-")
return(s)
}
velodata2[["spliced"]]@Dimnames[[2]] = as.character(lapply(velodata2[["spliced"]]@Dimnames[[2]],func))
velodata2[["unspliced"]]@Dimnames[[2]] = as.character(lapply(velodata2[["unspliced"]]@Dimnames[[2]],func))
velodata2[["ambiguous"]]@Dimnames[[2]] = as.character(lapply(velodata2[["ambiguous"]]@Dimnames[[2]],func))
func <- function(s)
{
s <- strsplit(s,".*:",fixed = F)[[1]][2]
s <- strsplit(s,"x",fixed = T)[[1]]
s <- paste(s,"5",sep = "-")
return(s)
}
velodata3[["spliced"]]@Dimnames[[2]] = as.character(lapply(velodata3[["spliced"]]@Dimnames[[2]],func))
velodata3[["unspliced"]]@Dimnames[[2]] = as.character(lapply(velodata3[["unspliced"]]@Dimnames[[2]],func))
velodata3[["ambiguous"]]@Dimnames[[2]] = as.character(lapply(velodata3[["ambiguous"]]@Dimnames[[2]],func))
# CA_dataset2 <- readRDS("CA_dataset2.rds")
ds2_AC <- readRDS("ds2_AC.rds")
sp1_velo <- as.Seurat(x = velodata1)
sp2_velo <- as.Seurat(x = velodata2)
sp3_velo <- as.Seurat(x = velodata3)
merge_velo <- merge(sp1_velo, c(sp2_velo,sp3_velo))
merge_velo <- subset(merge_velo, cells = WhichCells(ds2_AC))
rm(sp1_velo)
rm(sp2_velo)
rm(sp3_velo)
rm(velodata1)
rm(velodata2)
rm(velodata3)
merge_velo <- readRDS("dataset2_PA_velo.RDS")
Loading required package: Seurat
Registered S3 method overwritten by 'data.table':
method from
print.data.table
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
# saveRDS(merge_velo,"dataset2_AC_velo.RDS")
# merge_velo <- readRDS("dataset2_AC_velo.RDS")
ident.colors <- colors_list[1:length(x = levels(x = merge_velo))]
names(x = ident.colors) <- levels(x = merge_velo)
cell.colors <- ident.colors[Idents(object = merge_velo)]
names(x = cell.colors) <- colnames(x = merge_velo)
png("velocity.png")
show.velocity.on.embedding.cor(emb = Embeddings(object = merge_velo, reduction = "umap"), vel = Tool(object = merge_velo, slot = "RunVelocity"), n = 200, scale = "sqrt", cell.colors = ac(x = cell.colors, alpha = 0.5),
cex = 0.8, arrow.scale = 3, show.grid.flow = TRUE, min.grid.cell.mass = 0.5, grid.n = 40, arrow.lwd = 1,
do.par = FALSE, cell.border.alpha = 0.1)
delta projections ... sqrt knn ... transition probs ... done
calculating arrows ... done
grid estimates ... grid.sd= 0.5051766 min.arrow.size= 0.01010353 max.grid.arrow.length= 0.04539128 done
dev.off()
null device
1
# plot <- tSNE.velocity.plot(vel = Tool(object = sp1_velo, slot = "RunVelocity"))
source("../vascular-analysis/seuratToAnnDataCombined.R")
h5ad_output <- "AC_SMC_velo.h5ad"
library(reticulate)
library(Matrix)
writeMM(t(merge_velo@assays$RNA@counts), file='combined.mtx')
NULL
writeMM(t(merge_velo@assays$spliced@counts), file='spliced.mtx')
NULL
writeMM(t(merge_velo@assays$unspliced@counts), file='unspliced.mtx')
NULL
write.csv(rownames(merge_velo@assays$spliced@counts), file = "genes.csv", row.names = FALSE)
write.csv(merge_velo@reductions$umap@cell.embeddings, file = "umap.csv", row.names = FALSE)
write.csv(merge_velo@reductions$pca@cell.embeddings, file = "pca.csv", row.names = FALSE)
write.csv(colnames(merge_velo@assays$spliced@counts), file = "cells.csv", row.names = FALSE)
write.csv(merge_velo@meta.data, file = "meta.csv", row.names = FALSE)
source_python('~/scRNAseq/vascular-analysis/build.py')
build(h5ad_output, pca = TRUE, umap = TRUE)
file.remove('combined.mtx')
[1] TRUE
file.remove('spliced.mtx')
[1] TRUE
file.remove('unspliced.mtx')
[1] TRUE
file.remove('genes.csv')
[1] TRUE
file.remove('cells.csv')
[1] TRUE
file.remove('umap.csv')
[1] TRUE
file.remove('pca.csv')
[1] TRUE
file.remove('meta.csv')
[1] TRUE
velodata1 <- ReadVelocity(file ="./velo_data/CARconDIS.loom")
reading loom file via hdf5r...
velodata2 <- ReadVelocity(file ="./velo_data/CARconDIS0620.loom")
reading loom file via hdf5r...
velodata3 <- ReadVelocity(file ="./velo_data/CARconDIS0717.loom")
reading loom file via hdf5r...
#匹配两次的barcode
func <- function(s)
{
s <- strsplit(s,".*:",fixed = F)[[1]][2]
s <- strsplit(s,"x",fixed = T)[[1]]
s <- paste(s,"2",sep = "-")
return(s)
}
velodata1[["spliced"]]@Dimnames[[2]] = as.character(lapply(velodata1[["spliced"]]@Dimnames[[2]],func))
velodata1[["unspliced"]]@Dimnames[[2]] = as.character(lapply(velodata1[["unspliced"]]@Dimnames[[2]],func))
velodata1[["ambiguous"]]@Dimnames[[2]] = as.character(lapply(velodata1[["ambiguous"]]@Dimnames[[2]],func))
func <- function(s)
{
s <- strsplit(s,".*:",fixed = F)[[1]][2]
s <- strsplit(s,"x",fixed = T)[[1]]
s <- paste(s,"4",sep = "-")
return(s)
}
velodata2[["spliced"]]@Dimnames[[2]] = as.character(lapply(velodata2[["spliced"]]@Dimnames[[2]],func))
velodata2[["unspliced"]]@Dimnames[[2]] = as.character(lapply(velodata2[["unspliced"]]@Dimnames[[2]],func))
gc()
used (Mb) gc trigger (Mb) max used (Mb)
Ncells 9626592 514.2 17054862 910.9 17054862 910.9
Vcells 1092743890 8337.0 2184824865 16668.9 2127190354 16229.2
velodata2[["ambiguous"]]@Dimnames[[2]] = as.character(lapply(velodata2[["ambiguous"]]@Dimnames[[2]],func))
func <- function(s)
{
s <- strsplit(s,".*:",fixed = F)[[1]][2]
s <- strsplit(s,"x",fixed = T)[[1]]
s <- paste(s,"6",sep = "-")
return(s)
}
velodata3[["spliced"]]@Dimnames[[2]] = as.character(lapply(velodata3[["spliced"]]@Dimnames[[2]],func))
velodata3[["unspliced"]]@Dimnames[[2]] = as.character(lapply(velodata3[["unspliced"]]@Dimnames[[2]],func))
velodata3[["ambiguous"]]@Dimnames[[2]] = as.character(lapply(velodata3[["ambiguous"]]@Dimnames[[2]],func))
# ds2_PA <- readRDS("ds2_PA.rds")
sp1_velo <- as.Seurat(x = velodata1)
sp2_velo <- as.Seurat(x = velodata2)
sp3_velo <- as.Seurat(x = velodata3)
merge_velo <- merge(sp1_velo, c(sp2_velo,sp3_velo))
merge_velo <- subset(merge_velo, cells = WhichCells(ds2_PA))
rm(sp1_velo)
rm(sp2_velo)
rm(sp3_velo)
rm(velodata1)
rm(velodata2)
rm(velodata3)
Idents(merge_velo) <- merge_velo$Classification1
错误: Cannot find 'Classification1' in this Seurat object
h5ad_output <- "PA_SMC_velo.h5ad"
library(reticulate)
library(Matrix)
writeMM(t(merge_velo@assays$RNA@counts), file='combined.mtx')
NULL
writeMM(t(merge_velo@assays$spliced@counts), file='spliced.mtx')
NULL
writeMM(t(merge_velo@assays$unspliced@counts), file='unspliced.mtx')
NULL
write.csv(rownames(merge_velo@assays$spliced@counts), file = "genes.csv", row.names = FALSE)
write.csv(merge_velo@reductions$umap@cell.embeddings, file = "umap.csv", row.names = FALSE)
write.csv(merge_velo@reductions$pca@cell.embeddings, file = "pca.csv", row.names = FALSE)
write.csv(colnames(merge_velo@assays$spliced@counts), file = "cells.csv", row.names = FALSE)
write.csv(merge_velo@meta.data, file = "meta.csv", row.names = FALSE)
source_python('~/scRNAseq/vascular-analysis/build.py')
build(h5ad_output, pca = TRUE, umap = TRUE)
file.remove('combined.mtx')
[1] TRUE
file.remove('spliced.mtx')
[1] TRUE
file.remove('unspliced.mtx')
[1] TRUE
file.remove('genes.csv')
[1] TRUE
file.remove('cells.csv')
[1] TRUE
file.remove('umap.csv')
[1] TRUE
file.remove('pca.csv')
[1] TRUE
file.remove('meta.csv')
[1] TRUE
SMC_velo <- subset(merge_velo, idents = "SMC")
RunVelocity(object = SMC_velo, deltaT = 1, kCells = 25, fit.quantile = 0.02)
ident.colors <- colors_list[1:length(x = levels(x = SMC_velo))]
names(x = ident.colors) <- levels(x = SMC_velo)
cell.colors <- ident.colors[Idents(object = SMC_velo)]
names(x = cell.colors) <- colnames(x = SMC_velo)
png("SMC_velocity.png")
show.velocity.on.embedding.cor(emb = Embeddings(object = SMC_velo, reduction = "umap"), vel = Tool(object = SMC_velo, slot = "RunVelocity"), n = 200, scale = "sqrt", cell.colors = ac(x = cell.colors, alpha = 0.5),
cex = 0.8, arrow.scale = 3, show.grid.flow = TRUE, min.grid.cell.mass = 0.5, grid.n = 40, arrow.lwd = 1,
do.par = FALSE, cell.border.alpha = 0.1)
dev.off()
Add a new chunk by clicking the Insert Chunk button on the toolbar or by pressing Ctrl+Alt+I.
When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Ctrl+Shift+K to preview the HTML file).
The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.